<template>
  <div class="child2">
    <h1>我是Child2组件</h1>
    <h2>我得到的牛奶是：{{niunai}}</h2>
  </div>
</template>

<script>
  export default {
    name:'Child2',
    data() {
      return {
        niunai:''
      }
    },
    methods: {
      saveMilk(value){
        console.log('Child2收到了牛奶：',value)
        this.niunai = value
      }
    },
    created() {
      this.$bus.$on('send-milk',this.saveMilk)
    },
    beforeDestroy() {
      this.$bus.$off('send-milk')
    },
  }
</script>

<style>
  .child2 {
    background-color: green;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px black;
  }
</style>